<template>
  <div>
    <van-cell title="搜索历史">
      <van-icon name="delete-o" @click="isShow = true" v-if="!isShow" />
      <div v-else>
        <span @click="$store.commit('SET_HISTORIES', [])">全部删除</span>
        &nbsp;<span @click="isShow = false">完成</span>
      </div>
    </van-cell>
    <van-cell :title="item" v-for="item in $store.state.histories" :key="item" @click="$emit('update-keywords',item)"
      ><van-icon name="close" @click="del(item)" v-if="isShow"
    /></van-cell>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isShow: false
    }
  },
  methods: {
    del(item) {
      this.$store.commit(
        'SET_HISTORIES',
        this.$store.state.histories.filter((i) => i !== item)
      )
    }
  }
}
</script>

<style></style>
